package practise.alogrithm.hundredInterviewQuestions;

import practise.alogrithm.hundredInterviewQuestions.Utils.TreeNode;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * Created by richard on 6/2/14.
 */
public class MinorTree {
    public static TreeNode getTreeMinor(TreeNode head){
        if(head.getLeft()==null&&head.getRight()==null){
            return head;
        }
        if(head==null){
            return null;
        }
        TreeNode tempNode = head.getLeft();
        getTreeMinor(head.getRight());
        getTreeMinor(head.getLeft());
        head.setLeft(head.getRight());
        head.setRight(tempNode);
        return head;
    }

    public static TreeNode getTreeMinorInWhile(TreeNode head){
        Queue<TreeNode> treeNodes = new LinkedList<>();
        treeNodes.add(head);
        while(!treeNodes.isEmpty()){
            TreeNode tempNode = treeNodes.poll();
            TreeNode treeNode;
            treeNode=tempNode.getLeft();
            tempNode.setLeft(tempNode.getRight());
            tempNode.setRight(treeNode);
            treeNodes.offer(tempNode.getLeft());
            treeNodes.offer(tempNode.getRight());
        }
        return head;
    }
}
